package com.example.superoa.controller;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.example.superoa.model.pojos.Department;
import com.example.superoa.model.pojos.Jobchage;
import com.example.superoa.model.service.DepartmentService;
import com.example.superoa.model.service.JobchageService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


@Controller
public class RenshiController {
	@Autowired
	private DepartmentService departmentService;
	
	@Autowired
	private JobchageService jobchageservice;
	//个人中心
	@RequestMapping("grzx")
	public void demo1() {
	}
	//入职管理
	@RequestMapping("ljj-entry")
	public void entry() {
	}
	//转正管理
	@RequestMapping("ljj-become-worker")
	public void becomeworker() {
	}
	//奖惩管理
	@RequestMapping("ljj-rsaps")
	public void Rsaps() {
	}
	//调动管理
	@RequestMapping("ljj-transfer")
	public void transfer() {
	}
	//离职管理
	@RequestMapping("ljj-rank-approval")
	public void Rankpproval() {
	}
	//职务管理
	@RequestMapping("ljj-jobchage")
	public void Jobchage() {
	}
	//职务分类
	@RequestMapping("ljj-jobchagetype")
	public void JobchageType() {
	}
	//职位管理
	@RequestMapping("ljj-position")
	public void Position() {
	}
	//详情页
	@RequestMapping("ljj-renshixq")
	public void Renshixq() {
	}
	
	/*获取部门数据*/
	@RequestMapping("Department_list")
	@ResponseBody
	public Map<String,Object> Departmentlist(int page,int rows){
		Map<String,Object> map = new HashMap<>();
		//先分页
		Page<Object> pg = PageHelper.startPage(page, rows);
		
		List<Department> i=departmentService.departmentAll();
		//总记录
		map.put("total", pg.getTotal());
		//页内容
		map.put("rows", i);
		return map;
	}
	//级联
	@RequestMapping("Department_listt")
	@ResponseBody
	public List<Department> Departmentlistt(){
		return departmentService.departmentAll();
	}
	//编辑部门
	@RequestMapping("bj-form")
	@ResponseBody
	public Department BjForm(int depart_id,Model model) {
		System.err.println(departmentService.departmentById(depart_id).getDepartName());
		return departmentService.departmentById(depart_id);
	}
	
	
	//新增一条部门数据
	@PostMapping("add-dept")
	public String addDept(Department d) {
		departmentService.adddepartment(d);;
		return "redirect:main-administrator:department";
	}
	//删除
	@RequestMapping("delete-department")
	@ResponseBody
	public void DeleteDepartment(@Param("departid")int departid) {
		try {
			System.out.println(departid);
		} catch (Exception e) {
			// TODO: handle exception
		}
		departmentService.deletedepartmentid(departid);
	}
	//修改
	@PostMapping("xiugai")
	@ResponseBody
	public void xiugai(Department depart_id) {
		System.err.println(depart_id);
		departmentService.xiugai(depart_id);
	}
	
	
	
	//职务规划获取数据
	@RequestMapping("jobchage_list")
	@ResponseBody
	public Map<String,Object> jobchageAll(int page,int rows){
		Map<String,Object> map = new HashMap<>();
		//先分页
		Page<Object> pg = PageHelper.startPage(page, rows);
		
		List<Jobchage> i=jobchageservice.jobchageAll();
		//总记录
		map.put("total", pg.getTotal());
		//页内容
		map.put("rows", i);
		return map;
	}
	//新增职务
	@PostMapping("add-jobchage")
	public String addJobchage(Jobchage j) {
		jobchageservice.addjobchage(j);
		return "redirect:main-administrator:ljj-jobchage";
		
	}

	//删除
	@RequestMapping("delete-jobchage")
	@ResponseBody
	public void DeleteJobchage(int jobchageId) {
		try {
			System.out.println(jobchageId);
		} catch (Exception e) {
			// TODO: handle exception
		}
		jobchageservice.deletedepartmentid(jobchageId);
	}
	//获取职务编辑信息里面的数据
	@RequestMapping("jobchage-bjxx")
	@ResponseBody
	public Jobchage JobchageBjxx(int jobchageId,Model model) {
		System.err.println(jobchageservice.jobchageById(jobchageId).getJobchageName());
		return jobchageservice.jobchageById(jobchageId);
	}
	//职务修改
	@PostMapping("jobchage-xiugai")
	@ResponseBody
	public void xiugai(Jobchage jobchageId) {
		System.err.println(jobchageId);
		jobchageservice.jobchageedit(jobchageId);
	}
}
